<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="ajax.js" charset="UTF-8"></script>
    <script type="text/javascript">
        window.onload=function(){
            var oUser = document.getElementById('user')
            var oPass = document.getElementById('pass')
            var oBtn  = document.getElementById('btn')
            
            oBtn.onclick = ()=>{
                ajax({
                    url:'/login',
                    data:{user:oUser.value,pass:oPass.value},
                    success:(str)=>{
                        var data = eval('('+str+')')
                        if(data.ok==true){
                            alert('登陆成功')
                        }else{
                            alert('失败'+data.msg)
                        }
                    },
                    error:()=>{
                        alert('通信错误')
                    }
                })
            }
        }
    </script>
</head>
<body>
    用户：<input type="text" id="user"/><br>
    密码：<input type="password" id="pass"/><br>
    <input type="button" value="提交" id="btn">
</body>
</html>